#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;

//Memory search
const int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
int r, c;
int h[105][105];
int len[105][105];

int dfs(int i, int j)
{
    if (len[i][j] != 0)
        return len[i][j];
    int ans = 0;
    for (int k = 0; k < 4; k++)
    {
        int x = i + dir[k][0];
        int y = j + dir[k][1];
        if (x >= 0 && x < r && y >= 0 && y < c && h[x][y] < h[i][j])
            ans = max(ans, dfs(x, y) + 1);
        else
            ans = max(ans, 1);
    }
    len[i][j] = ans;
    return ans;
}

int main()
{
    memset(h, 0, sizeof(h));
    memset(len, 0, sizeof(len));
    cin >> r >> c;
    for (int i = 0; i < r; i++)
        for (int j = 0; j < c; j++)
            cin >> h[i][j];

    int ans = 0;
    for (int i = 0; i < r; i++)
        for (int j = 0; j < c; j++)
            ans = max(ans, dfs(i, j));
    cout << ans << endl;
    return 0;
}
